package com.example.gulimallproduct.controller;



import com.example.gulimallproduct.request.PageBrandRequest;
import com.example.gulimallproduct.request.SaveBrandRequest;
import com.example.gulimallproduct.request.UpdateBrandRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.example.gulimallproduct.entity.BrandEntity;
import com.example.gulimallproduct.service.BrandService;
import com.example.common.utils.R;



/**
 * 品牌
 *
 * @author zzl
 * @email zzl@gmail.com
 * @date 2025-10-24 15:22:38
 */
@RestController
@RequestMapping("/brand")
@Slf4j
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(@Validated @RequestBody PageBrandRequest params){
        log.info("fenye查询品牌:{}", params);
        return brandService.selectPage(params);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Validated @RequestBody SaveBrandRequest brand){
        BrandEntity brandEntity = new BrandEntity();
        BeanUtils.copyProperties(brand, brandEntity);
        brandService.save(brandEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@Validated @RequestBody UpdateBrandRequest brand){
        log.info("修改品牌:{}", brand);
		BrandEntity brandEntity = new BrandEntity();
        BeanUtils.copyProperties(brand, brandEntity);


        return brandService.updateBrand(brandEntity);
    }
    @PostMapping("/update/status")
    public R updateStatus(String brandId, Integer status){
        log.info("修改品牌状态:{}", brandId);
        brandService.lambdaUpdate()
                .set(BrandEntity::getShowStatus, status)
                .eq(BrandEntity::getBrandId, brandId)
                .update();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
        log.info("删除品牌:{}", brandIds);
        return  brandService.del(brandIds);
    }

}
